package com.commons.DBPool;

import java.io.FileInputStream;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import com.game.logger.DBLogger;


/**
 * 
 * 数据库连接池配置
 * @author CHENLEI
 *
 */
public class DBManager {
	/**
	 * 閥值和定时机制管理内存
	 */
	public static boolean isRunning=true;
	public  static String dataDriver="";//驱动
	public  static String  url="";//连接串
	public  static String  username="";//连接串
	public  static String  password="";//连接串
	
	
	public static int Port=0;//端口号
	public static byte ThreadMax=0;//dispatcher线程数量
	public static byte poolsNum=0;//线程池线程的数量
	/***
	 * 初始化数据库基础数据
	 */
	public static  void IntiData(){
		try {
			DBLogger.logger.info("res/basedata.xml is start......");
			InputStream in=new FileInputStream("res/basedata.xml");
			SAXReader re=new SAXReader();
			Document doc=re.read(in);
			Element el=null;
			Iterator<?> ite=doc.selectNodes("sys").iterator();// 重根节点开始迭代,返回节点集合
			while(ite.hasNext()){
				el=(Element)ite.next();//取出根节点,遍历每个子节点，子节点可能也是父节点（sys1）
				dataDriver=el.elementText("dataDriver").trim();//取出子节点的值
				url=el.elementText("url").trim();
				username=el.elementText("username").trim();
				password=el.elementText("password").trim();
				
				ThreadMax=Byte.parseByte(el.elementText("ThreadMax").trim());
				poolsNum=Byte.parseByte(el.elementText("poolsNum").trim());
				Port=Integer.parseInt(el.elementText("Port").trim());
				
			 }
			} catch (Exception e) {
		}
	}
	
}
